//
//  ThemenViewController.m
//  Lextra Junior ueb IT
//
//  Created by Dirk Lieder on 27.05.11.
//  Copyright 2011 Phosphon. All rights reserved.
//
#define RGB(r, g, b) \
[UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

#import "ThemenViewController.h"
#import "Lextra_Engine.h"
#import "NavigationViewController.h"
#import "AsyncImageView.h"

#import "Lextra_Engine.h"

//ADDED BY LDHAI
#import "Global.h"

@implementation ThemenViewController

@synthesize myTableView;
//__NGUYEN_HUY_SON
@synthesize splitThemen;
@synthesize tabBarController;
@synthesize woerPre;
@synthesize tabBarControllerThemmen;
//___END_NGUYEN_HUY_SON__
//____________________________

//ADDED BY LDHAI
@synthesize labelThemenView;

- (BOOL)isPadPortrait
{
    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
            && (self.interfaceOrientation == UIInterfaceOrientationPortrait
                || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
//_________END_NGUYEN_HUY_SON____
static NSMutableArray *listData; // list


- (void)setDelegate:(id)new_delegate{
	Delegate = new_delegate;
}
// akt display
- (void)aktDisplay{
     [myTableView reloadData];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    bIsSelectWimmel = TRUE;
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [labelThemenView release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        CGFloat navBarHeight = 44.0f;    
        CGRect frame = CGRectMake(self.navigationController.navigationBar.frame.origin.x, self.navigationController.navigationBar.frame.origin.y, self.navigationController.navigationBar.frame.size.width, navBarHeight);
        [self.navigationController.navigationBar setFrame:frame];
        [self.navigationController.navigationBar setBackgroundColor:[[UIColor alloc] initWithRed:134 green:166 blue:228 alpha:1.0]];
        
        //__NGUYEN_HUY_SON___
        UIImageView *imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iPad_table_Themen.png"]];
        [self.navigationController.navigationBar addSubview:imageView1];
        [imageView1 release];
    }

    // Build the array static  
    listData = [[NSMutableArray alloc] init];
        
	[listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"liste", @"typ",@"Colori" , @"name", @"Farben", @"beschreibung", @"", @"bild", @"*Farben", @"wimmelbild", @"0",@"wimmelnummer",nil]];
	[listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"liste", @"typ",@"Numeri" , @"name", @"Zahlen", @"beschreibung", @"", @"bild", @"*Zahlen", @"wimmelbild",  @"0",@"wimmelnummer",nil]];
	[listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"liste", @"typ",@"Forme" , @"name", @"Formen", @"beschreibung", @"", @"bild", @"*Formen", @"wimmelbild",  @"0",@"wimmelnummer",nil]];
	[listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"La mia famiglia" , @"name", @"Meine Familie", @"beschreibung", @"", @"bild", @"Familie", @"wimmelbild",  @"0",@"wimmelnummer",nil]];
	[listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"La nostra casa" , @"name", @"Unser Haus", @"beschreibung", @"", @"bild", @"Haus", @"wimmelbild",  @"0",@"wimmelnummer",nil]];
    [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"Grande e piccolo 1" , @"name", @"Groß und klein 1", @"beschreibung", @"", @"bild", @"Groß und klein 1", @"wimmelbild",  @"0",@"wimmelnummer",nil]];
    [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"Grande e piccolo 2" , @"name", @"Groß und klein 2", @"beschreibung", @"", @"bild", @"Groß und klein 2", @"wimmelbild",  @"0",@"wimmelnummer",nil]];
    [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"Dove sono? 1" , @"name", @"Wo sind sie? 1", @"beschreibung", @"", @"bild", @"Park 1", @"wimmelbild",  @"0",@"wimmelnummer",nil]];
    [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"Dove sono? 2" , @"name", @"Wo sind sie? 2", @"beschreibung", @"", @"bild", @"Park 2", @"wimmelbild",  @"0",@"wimmelnummer",nil]];
    [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"Cosa puoi fare 1" , @"name", @"Was du tun kannst 1", @"beschreibung", @"", @"bild", @"Klassenzimmer", @"wimmelbild",  @"0",@"wimmelnummer",nil]];    
    [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"Cosa puoi fare 2" , @"name", @"Was du tun kannst 2", @"beschreibung", @"", @"bild", @"Schulhof", @"wimmelbild",  @"0",@"wimmelnummer",nil]];    
    [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"Cosa puoi fare 3" , @"name", @"Was du tun kannst 3", @"beschreibung", @"", @"bild", @"Theater", @"wimmelbild",  @"0",@"wimmelnummer",nil]];    
    [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"Cosa puoi fare 4" , @"name", @"Was du tun kannst 4", @"beschreibung", @"", @"bild", @"Turnhalle", @"wimmelbild",  @"0",@"wimmelnummer",nil]];    
    [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"Che ore sono?" , @"name", @"Wie spät ist es?", @"beschreibung", @"", @"bild", @"Uhrzeit", @"wimmelbild",  @"0",@"wimmelnummer",nil]];    
    [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"Giorno e notte" , @"name", @"Tag und Nacht", @"beschreibung", @"", @"bild", @"Tagesablauf", @"wimmelbild",  @"0",@"wimmelnummer",nil]];    
    [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"I mesi" , @"name", @"Die Monate", @"beschreibung", @"", @"bild", @"*Monate", @"wimmelbild",  @"0",@"wimmelnummer",nil]];    
    [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"I giorni della settimana" , @"name", @"Die Wochentage", @"beschreibung", @"", @"bild", @"*Tage", @"wimmelbild",  @"0",@"wimmelnummer",nil]];    
    [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"Il tempo" , @"name", @"Das Wetter", @"beschreibung", @"", @"bild", @"Wetter", @"wimmelbild",  @"0",@"wimmelnummer",nil]];    
    [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"Le quattro stagioni 1" , @"name", @"Die vier Jahreszeiten 1", @"beschreibung", @"", @"bild", @"Jahreszeiten links", @"wimmelbild",  @"0",@"wimmelnummer",nil]];    
   [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"Le quattro stagioni 2" , @"name", @"Die vier Jahreszeiten 2", @"beschreibung", @"", @"bild", @"Jahreszeiten rechts", @"wimmelbild",  @"0",@"wimmelnummer",nil]];  
    [listData addObject:[[NSDictionary alloc] initWithObjectsAndKeys:@"wimmelbild", @"typ",@"Le quattro stagioni 3" , @"name", @"Die vier Jahreszeiten 3", @"beschreibung", @"", @"bild", @"Dreikoenigsfest", @"wimmelbild",  @"0",@"wimmelnummer",nil]];  
   
    
    // Show the string values  
    // for (NSString *str in listData)
    //    NSLog(@"--%@", str);
    
    [myTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [myTableView reloadData];
    

           
    NSDictionary *infoArray = (NSDictionary*)[listData objectAtIndex:0];
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        NSArray *myPoindInfo = (NSArray*)[woerPre getPoindInfo:[infoArray objectForKey:@"wimmelbild"] num:[[infoArray objectForKey:@"wimmelnummer"]intValue]];
        wimmelListView = [[WimmelListViewController alloc] initWithNibName:@"WimmelListViewController-iPad" bundle:nil];
        NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, wimmelListView, nil];
        splitThemen.viewControllers = viewControllers;            
        
        wimmelListView.woerPre = woerPre;
        
        [wimmelListView setDelegatePlud:self para:myPoindInfo];
        [viewControllers release];
        intDidselect = 1;
        self.contentSizeForViewInPopover = CGSizeMake(310, self.myTableView.rowHeight*19.0);
    }
    
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}



#pragma mark - tableView

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{	
    return 100;			
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [listData count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
	
	NSUInteger row = [indexPath row];
	UITableViewCell *cell;
	
	static NSString *CustomCellIdentifier;
    
    // Eintrag
    CustomCellIdentifier = @"part1";
    cell = [tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
    if (cell == nil) {
        // new cell
        cell = [self getCell:CustomCellIdentifier];
    }
    
    NSDictionary *Pointer = [listData objectAtIndex:row];
    
    
    UILabel *descriptionLabel = (UILabel*)[cell.contentView viewWithTag:1];
    
    
    NSMutableString *tmpString1 = [[NSMutableString alloc] initWithString:[Pointer objectForKey:@"name"]];
    NSMutableString *tmpString2 = [[NSMutableString alloc] initWithString:[Pointer objectForKey:@"beschreibung"]];
    //___NGUYEN_HUY_SON__
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        cell.backgroundColor = [UIColor colorWithRed:172.0/255.0 green:173.0/255.0 blue:175.0/255.0 alpha:1.0];
    }   
    //___END_NGUYEN
    descriptionLabel.frame = CGRectMake(100, 18, 195, 50);
    descriptionLabel.text = tmpString1;
    CGSize expectedLabelSize = [descriptionLabel.text sizeWithFont:descriptionLabel.font 
                                                 constrainedToSize:descriptionLabel.frame.size
                                                     lineBreakMode:UILineBreakModeWordWrap];
    descriptionLabel.frame = CGRectMake(100, 18, 195, expectedLabelSize.height);
    

    
    UILabel *descriptionLabel2 = (UILabel*)[cell.contentView viewWithTag:2];    

    descriptionLabel2.frame = CGRectMake(100, 18, 195, 50);
    descriptionLabel2.text = tmpString2;

    CGSize expectedLabelSize2 = [descriptionLabel2.text sizeWithFont:descriptionLabel2.font 
                                                   constrainedToSize:descriptionLabel2.frame.size
                                                       lineBreakMode:UILineBreakModeWordWrap];
    descriptionLabel2.frame = CGRectMake(100, 18, 195, expectedLabelSize2.height);
    descriptionLabel2.center = CGPointMake(descriptionLabel2.center.x, descriptionLabel.bounds.size.height+18 + descriptionLabel2.bounds.size.height/2  );
    
    [tmpString1 release];
    [tmpString2 release];
    
    
    AsyncImageView *descriptionImage = (AsyncImageView*)[cell.contentView viewWithTag:3];
        
    NSMutableString *myName = [[NSMutableString alloc] initWithString:[Pointer objectForKey:@"bild"]];
                               
    NSString *substring;
    if([myName length] > 2){
        if([myName hasSuffix:@".tif"]){
            substring = [[myName substringToIndex:[myName length]-4] stringByAppendingString:@"_k"];
        } else {
            substring = [myName stringByAppendingString:@"_k"];
        }
    } else {
        substring = [[NSString alloc] initWithString:@"pirat_k"];
    }
    //NSLog(@"laenge *%@*%d", myName,[myName length]);
    
    [descriptionImage asyncImageLoad:substring];
    
    
    return cell;
}



#pragma mark -
#pragma mark Table Delegate Methods 


-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    return indexPath; 
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
	NSInteger row = [indexPath row];
    NSLog(@"ThemenViewController - tableView:didSelectRowAiIndexPath");
	
    // show detailcard
    NSDictionary *infoArray = (NSDictionary*)[listData objectAtIndex:row];
    //[Delegate jmpTo:@"wimmel" name:@"a..c" thePara:infoArray];
    //___NGUYEN_HUY_SON___
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        if (splitThemen.pc != nil) 
        {
            [splitThemen.pc dismissPopoverAnimated:YES];
        }

        if (intDidselect == 1) {
            [wimmelListView release];
        }
        if (intDidselect == 2) {
            [wimmelView release];
        }
        NSArray *myPoindInfo = (NSArray*)[woerPre getPoindInfo:[infoArray objectForKey:@"wimmelbild"] num:[[infoArray objectForKey:@"wimmelnummer"]intValue]];
        
        if([[(NSDictionary*)myPoindInfo objectForKey:@"wimmelbild"] hasPrefix:@"*"])
        {
            wimmelListView = [[WimmelListViewController alloc] initWithNibName:@"WimmelListViewController-iPad" bundle:nil];
            NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, wimmelListView, nil];
            splitThemen.viewControllers = viewControllers;            
            
            wimmelListView.woerPre = woerPre;

            if([self isPadPortrait] == TRUE)
            {
                if (splitThemen.barButton != nil) 
                {
                    [wimmelListView showRootPopoverButtonItem:splitThemen.barButton];
                }
            }
            [wimmelListView setDelegatePlud:self para:myPoindInfo];
            [viewControllers release];
            intDidselect = 1;
            
            //ADDED BY LDHAI
            for(UIView * label in self.tabBarController.tabBar.subviews)
            {
                if([label isMemberOfClass:[UILabel class]])
                    [label removeFromSuperview];
            }
            themenHintStatus = NO;
        } 
        else 
        {
            wimmelView=  [[WimmelViewController alloc] initWithNibName:@"wimmelView-iPad" bundle:nil];
            NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, wimmelView, nil];
            splitThemen.viewControllers = viewControllers;            
            wimmelView.woerPre = woerPre;
            
            if([self isPadPortrait] == TRUE)
            {
                if (splitThemen.barButton != nil) {
                    [wimmelView showRootPopoverButtonItem:splitThemen.barButton];
                }
            }
            wimmelView.tabbarControllerRoot = tabBarController;
            [wimmelView setDelegatePlud:self para:myPoindInfo bIsParentThemmen:YES];
            [viewControllers release];
            intDidselect = 2;
            
            //ADDED BY LDHAI
//            labelThemenView = [[UILabel alloc] initWithFrame:CGRectMake(900, 10, 100, 30)];
//            labelThemenView.text = @"Bild berühren um Menü zu verstecken";
//            labelThemenView.font = [UIFont boldSystemFontOfSize:15.0];
//            labelThemenView.opaque = NO;
//            labelThemenView.backgroundColor = [UIColor underPageBackgroundColor];
//            labelThemenView.textAlignment = UITextAlignmentCenter;
//            labelThemenView.textColor = [UIColor blackColor];
//            labelThemenView.layer.cornerRadius = 10.0;
//            labelThemenView.layer.borderWidth = 1;
//            labelThemenView.layer.borderColor = [[UIColor blackColor] CGColor];
//            [self.tabBarController.tabBar addSubview:labelThemenView];
            
            themenHintStatus = YES;
        }
    }
    else//IF_IPHONE
    {
        NSArray *myPoindInfo = (NSArray*)[(Lextra_Engine*)Delegate getPoindInfo:[infoArray objectForKey:@"wimmelbild"] num:[[infoArray objectForKey:@"wimmelnummer"]intValue]];
        
        [(Lextra_Engine*)Delegate jmpTo:@"wimmel" name:@"a..c" thePara:myPoindInfo];
    }
    if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) 
    {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    }    //__NGUYEN_HUY_SON_END__

}



#pragma mark -
#pragma mark cell creation 
-(UITableViewCell*)getCell:(NSString*)myIdentifier{
	
	// new cell
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myIdentifier]autorelease];
	cell.userInteractionEnabled = YES;
    cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Empty.png"]] autorelease];
    cell.selectedBackgroundView.autoresizingMask = UIViewContentModeScaleToFill;
	
	// Text Label blue
	CGRect aframe = CGRectMake(100, 18, 195, 50);
	UILabel *textLabel = [[[UILabel alloc] initWithFrame:aframe] autorelease];
	
    textLabel.font = [UIFont fontWithName:@"TrebuchetMS-Bold" size:14];
	textLabel.numberOfLines=0;
    textLabel.lineBreakMode = UILineBreakModeWordWrap;
    textLabel.textColor = RGB(0x00, 0x3f, 0x9e);
    textLabel.highlightedTextColor = RGB(0x40, 0x7f, 0xde);
	textLabel.backgroundColor = [UIColor colorWithWhite:1.00 alpha:0.0];
	textLabel.clearsContextBeforeDrawing = YES;
	textLabel.tag = 1;
	//textLabel.frame = CGRectMake(textLabel.frame.origin.x,textLabel.frame.origin.y,320.0,textLabel.frame.size.height);
	[cell.contentView addSubview:textLabel];		
    
 	// Text Label blak
	aframe = CGRectMake(100, 18, 195, 50);
	textLabel = [[[UILabel alloc] initWithFrame:aframe] autorelease];
	
    textLabel.font = [UIFont fontWithName:@"TrebuchetMS-Italic" size:14];
	textLabel.numberOfLines=0;
    textLabel.lineBreakMode = UILineBreakModeWordWrap;
    textLabel.textColor = RGB(0x00, 0x00, 0x00);
    textLabel.highlightedTextColor = RGB(0x60, 0x60, 0x60);
	textLabel.backgroundColor = [UIColor colorWithWhite:1.00 alpha:0.0];
	textLabel.clearsContextBeforeDrawing = YES;
	textLabel.tag = 2;
	//textLabel.frame = CGRectMake(textLabel.frame.origin.x,textLabel.frame.origin.y,320.0,textLabel.frame.size.height);
	[cell.contentView addSubview:textLabel];		
    
    // image view async
    aframe = CGRectMake(5, 5, 90,90);
    AsyncImageView *topImageView;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        topImageView = [[AsyncImageView alloc] initWithFrame:aframe];
    }
    else
    {
        topImageView = [[[AsyncImageView alloc] initWithFrame:aframe] autorelease];
    }
     
    topImageView.tag = 3;
    topImageView.backgroundColor = [UIColor colorWithWhite:1.00 alpha:0.0];
    [cell.contentView addSubview:topImageView];	
	
    
	// trenner
	CGRect frame = CGRectMake(0, 99, 320,1);
	UIImageView *trennerImageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"listtrenner.png"]] autorelease];
	trennerImageView.frame = frame;
	[cell.contentView addSubview:trennerImageView];
    
    
	cell.contentView.backgroundColor = [UIColor colorWithWhite:1.00 alpha:0.0];
    
	return cell;
}




- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

//__NGUYEN_HUY_SON
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        return YES;
    }
    else
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
}
//___END_NGUYEN_HUY_SON___

//_______________NGUYEN_HUY_SON__________
- (void)splitViewController:(UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController:(UIPopoverController*)pc {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        // Keep references to the popover controller and the popover button, and tell the detail view controller to show the button.
        barButtonItem.title = @"Themen";
        splitThemen.pc = pc;
        splitThemen.barButton = barButtonItem;
        UIViewController <SubstitutableDetailViewController> *detailViewController = [splitThemen.viewControllers objectAtIndex:1];
        [detailViewController showRootPopoverButtonItem:splitThemen.barButton];
        
        //ADDED BY LDHAI
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iPad_tabbar2-portrait.png"]];
        
        if([currentViewController isEqualToString:@"Woerter"])
        {
            [imageView setImage:[UIImage imageNamed:@"iPad_tabbar1-portrait.png"]];
        }
        else if ([currentViewController isEqualToString:@"Themen"])
        {
            [imageView setImage:[UIImage imageNamed:@"iPad_tabbar2-portrait.png"]];
        }
        else if ([currentViewController isEqualToString:@"Spiele"])
        {
            [imageView setImage:[UIImage imageNamed:@"iPad_tabbar3-portrait.png"]];
        }
        else
        {
            [imageView setImage:[UIImage imageNamed:@"iPad_tabbar4-portrait.png"]];
        }
        
        //UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iPad_tabbar2-portrait.png"]];
        [self.tabBarController.tabBar addSubview:imageView];
        [imageView release];
        //myTableView.frame = CGRectMake(myTableView.frame.origin.x, myTableView.frame.origin.y, myTableView.frame.size.width, 674);
    }
}

- (void)splitViewController:(UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        // Nil out references to the popover controller and the popover button, and tell the detail view controller to hide the button.
        UIViewController <SubstitutableDetailViewController> *detailViewController = [splitThemen.viewControllers objectAtIndex:1];
        [detailViewController invalidateRootPopoverButtonItem:splitThemen.barButton];
        splitThemen.pc = nil;
        splitThemen.barButton = nil;
        
        //ADDED BY LDHAI
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iPad_tabbar2.png"]];
        
        if([currentViewController isEqualToString:@"Woerter"])
        {
            [imageView setImage:[UIImage imageNamed:@"iPad_tabbar1.png"]];
        }
        else if ([currentViewController isEqualToString:@"Themen"])
        {
            [imageView setImage:[UIImage imageNamed:@"iPad_tabbar2.png"]];
        }
        else if ([currentViewController isEqualToString:@"Spiele"])
        {
            [imageView setImage:[UIImage imageNamed:@"iPad_tabbar3.png"]];
        }
        else
        {
            [imageView setImage:[UIImage imageNamed:@"iPad_tabbar4.png"]];
        }
        
        //UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iPad_tabbar2.png"]];
        [self.tabBarController.tabBar addSubview:imageView];
        [imageView release];
        //myTableView.frame = CGRectMake(myTableView.frame.origin.x, myTableView.frame.origin.y, myTableView.frame.size.width, 674);
    }
}
 
@end
